"""
列表推导式
[exp for 子句]
[exp for 子句  更多的for子句或更多的if子句]
"""

# lst = [i for i in range(1, 10, 2)]
# print(lst)
#
# # 类比为
# lst = []
# for i in range(1, 10, 2):
#     lst.append(i)
# print(lst)

# lst = [(x, y) for x in range(1, 3) for y in range(2, 5) if y % 2]
# print(lst)
#
# # 类比为
# lst = []
# for x in range(1, 3):
#     for y in range(2, 5):
#         if y % 2:
#             lst.append((x, y))
# print(lst)

"""
[[1,4,7,0],
 [2,5,8,1],
 [3,6,9,2]]
"""
# lst = [[1, 2, 3],
#        [4, 5, 6],
#        [7, 8, 9],
#        [0, 1, 2]]
# res = []
# for i in range(3):
#     lst1 = []
#     for j in lst:
#         lst1.append(j[i])
#     res.append(lst1)
# print(res)
# # 反推为推导式
# lst = [[j[i] for j in lst] for i in range(3)]
# print(lst)

"""
字典推导式的格式:
{k:v for 子句}
{k:v for 子句 更多的for子句或更多的if子句}
"""

# d = {x: x ** 2 for x in range(5)}
# print(d)
#
# # 类比为
# d = {}
# for k in range(5):
#     d[k] = k ** 2
# print(d)
#
# d = {x: y for x in range(5) for y in range(6, 10)}
# print(d)

"""
集合推导式
{exp for 子句}
{exp for 子句  更多的for子句或更多的if子句}
"""
# s = {i for i in range(1, 10, 2)}
# print(s)
#
# # 类比为
# s = set()
# for i in range(1, 10, 2):
#     s.add(i)
# print(s)

s = {(i + k) for i in range(1, 10, 2) for k in range(1, 5, 2)}
print(s)